import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'index.dart';

class VideoView extends StatelessWidget {
  VideoView({
    Key? key,
    required this.url,
    required this.isShow,
  }) : super(key: key);
  final String url;
  final RxBool isShow;
  final controller = Get.put(VideoViewController());
  @override
  Widget build(BuildContext context) {
    if (controller.state.url != url) {
      controller.state.url = url;
      controller.state.isShow = isShow;
      controller.initialization();
    }
    return GetBuilder<VideoViewController>(
      init: controller,
      builder: (controller) {
        var state = controller.state;
        return state.chewieCtrl?.videoPlayerController.value.isInitialized ==
                true
            ? Chewie(controller: state.chewieCtrl!)
            : Container();
      },
    );
  }
}
